/*
 * @Author: your name
 * @Date: 2020-08-22 09:31:55
 * @LastEditTime: 2020-08-26 11:04:37
 * @LastEditors: 刘思源
 * @Description: In User Settings Ed
 * @FilePath: \examlist\src\store\getAuth\getAuth.js
 */

import { getRoom, addRoom, deleteRoom, editRoom } from '../../api/room'
import { Message } from 'view-design'
const state = {
  roomList: [] // 全部教室数据
}

const mutations = {
  getRooms(state, payload) { // 获取教室数据
    state.roomList = payload
  }
}

const actions = {
  async getRoomList({ commit }) { // 获取教室数据
    const { data: res } = await getRoom()
    commit('getRooms', res.data)
  },
  async addRoomList({ commit }, state) { // 添加教室
    // console.log(state, 'addd')
    const { data: res } = await addRoom(state)
    if (res.code === 1) {
      Message.success(res.msg)
    } else {
      Message.error(res.msg)
    }
  },
  async deleteRoomList({ commit }, id) { // 删除教室
    const { data: res } = await deleteRoom(id)
    if (res.code === 1) {
      Message.success(res.msg)
    } else {
      Message.error(res.msg)
    }
  },
  async editRoomItem({ commit }, form) { // 编辑教室
    const { data: res } = await editRoom(form)
    if (res.code === 1) {
      Message.success(res.msg)
    } else {
      Message.error(res.msg)
    }
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
